package Apps;

import Dao.UntilHive;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class ShowTable {
    Connection connection = null;
    Statement statement = null;
    ResultSet resultSet = null;

    public void showTable(String tableName){
        String sql = "show tables '" + tableName + "'";
        System.out.println("Running: " + sql);
        try {
            resultSet = statement.executeQuery(sql);

            if (resultSet.next()) {
                System.out.println(resultSet.getString(1));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public void describeTable(String tableName){
        String sql = "describe " + tableName;;
        System.out.println("Running: " + sql);
        try {
            resultSet = statement.executeQuery(sql);
            while (resultSet.next()) {
                System.out.println(resultSet.getString(1) + "\t" + resultSet.getString(2));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public void close(){
        UntilHive.closeAll(connection, statement, resultSet);
    }

    public static void main(String[] args){
        ShowTable showTable = new ShowTable();
        showTable.connection = UntilHive.getCon();
        try {
            showTable.statement = showTable.connection.createStatement();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        showTable.showTable("u_data");
        showTable.describeTable("u_data");
        showTable.close();

    }
}
